﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using HCI.Questionaire.Entities;

namespace HCI.Questionaire.QuestionGroup
{
    public abstract class ConsequenceQuestionGroup : QuestionGroupBase
    {
        private List<int> HistoryQuestions = new List<int>();

        public override int NextQuestion()
        {
            if (_currentQuestionIndex >= this._QuestionList.Count - 1)
                return _currentQuestionIndex;

            int oldIndex = _currentQuestionIndex;
            int nextIndex = -1;
            if (this._QuestionList[_currentQuestionIndex] is ConsequenceQuestion)
                nextIndex = ((ConsequenceQuestion)this._QuestionList[_currentQuestionIndex]).GetNextQuestionIndex();

            //int nextIndex = -1;
            if (nextIndex == -1)
                _currentQuestionIndex++;
            else if (nextIndex != 999)
                _currentQuestionIndex = nextIndex;

            if (nextIndex != 999)
            {
                this.OnQuestionIndexChanged();
                HistoryQuestions.Insert(0, oldIndex);
            }

            return CurrentQuestionIndex;
        }

        public override int PreviousQuestion()
        {
            if (_currentQuestionIndex <= 0)
                return _currentQuestionIndex;

            _currentQuestionIndex = HistoryQuestions[0];
            HistoryQuestions.RemoveAt(0);
            this.OnQuestionIndexChanged();
            return CurrentQuestionIndex;
        }


    }
}
